Skip to content

mysql-proxy: skip admin for no-FROM multi-expression selects; add tests#37391

Merged
terrymanu merged 1 commit into
apache:masterfrom
quanyeyang:fix-issue-37276
Dec 16, 2025
Merged

mysql-proxy: skip admin for no-FROM multi-expression selects; add tests#37391
terrymanu merged 1 commit into
apache:masterfrom
quanyeyang:fix-issue-37276

Conversation

@quanyeyang
Copy link
Copy Markdown
Contributor

Fixes #37276.

  • Root cause: when not using a database and executing no-FROM multi-expression SELECT, query is routed to admin branch;
    UnicastResourceShowExecutor rebuilds headers and rows from different sources, causing column-count mismatch and
    IndexOutOfBoundsException in DatabaseAdminQueryProxyBackendHandler.
    - Fix: routing-only. For normal no-FROM multi-expression SELECTs (non-sysvar, non-special functions), return Optional.empty() to use the
    standard pipeline; keep sysvar/special functions/no-resource behavior unchanged. No silent truncate/padding, aligned with maintainer’s
    suggestion.
    - Tests: add a test to assert skipping admin for multi-expression no-FROM; add a regression test to assert multi sysvars still use
    MySQLSystemVariableQueryExecutor.
    - Impact: minimal, routing only; no behavior change for existing admin executors.

    - Many thanks for the helpful feedback. Please let me know if anything else is required or the code is improper.
    

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.
  • I have updated the Release Notes of the current development version. For more details, see Update Release Note

@terrymanu terrymanu requested a review from Copilot December 15, 2025 17:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@terrymanu terrymanu requested a review from Copilot December 15, 2025 17:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +96 to +102
if (!isUseDatabase && isMultiExpressionSelect(sqlStatement)) {
return Optional.empty();
}
return isUseDatabase ? Optional.empty() : Optional.of(new UnicastResourceShowExecutor(sqlStatement, sql));
}

private static boolean isMultiExpressionSelect(final SelectStatement sqlStatement) {
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name isMultiExpressionSelect is ambiguous as it only checks if there are multiple projections, not specifically expressions. Consider renaming to hasMultipleProjections to more accurately reflect what the method validates.

Suggested change
if (!isUseDatabase && isMultiExpressionSelect(sqlStatement)) {
return Optional.empty();
}
return isUseDatabase ? Optional.empty() : Optional.of(new UnicastResourceShowExecutor(sqlStatement, sql));
}
private static boolean isMultiExpressionSelect(final SelectStatement sqlStatement) {
if (!isUseDatabase && hasMultipleProjections(sqlStatement)) {
return Optional.empty();
}
return isUseDatabase ? Optional.empty() : Optional.of(new UnicastResourceShowExecutor(sqlStatement, sql));
}
private static boolean hasMultipleProjections(final SelectStatement sqlStatement) {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@terrymanu terrymanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick, targeted fix. It cleanly addresses #37276 by rerouting no-FROM multi-projection selects away from the admin path (root cause of the column-count mismatch) while keeping sysvar and special-function handling intact. The added tests cover both the regression and sysvar behavior. I don’t see regressions or compatibility risk; LGTM to merge. Nice work!

@terrymanu terrymanu added this to the 5.5.3 milestone Dec 16, 2025
@terrymanu terrymanu merged commit 8597726 into apache:master Dec 16, 2025
145 checks passed
@quanyeyang
Copy link
Copy Markdown
Contributor Author

Thanks a lot for your detailed code review,it really helps me a lot,actually this is my first time taking part in open source activities,there are still many things for me to learn!

@quanyeyang quanyeyang deleted the fix-issue-37276 branch December 23, 2025 10:11
makssent pushed a commit to makssent/shardingsphere that referenced this pull request Apr 9, 2026
…ngsphere/master

* remotes/origin/master:
  mysql-proxy: skip admin for no-FROM multi-expression selects; add tests (apache#37391)
  Add CDCJobRunnerCleanerTest (apache#37398)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proxy] IndexOutOfBoundsException: Index: 2, Size: 2 when connecting with DataGrip due to metadata quer

4 participants